//
//  NSObject+Common.m
//  WhatEat
//
//  Created by Sunflower on 2018/7/14.
//  Copyright © 2018年 Sunflower. All rights reserved.
//

#import "NSObject+Common.h"

#import "SVProgressHUD.h"

@implementation NSObject (Common)

#pragma mark - SVProgressHUD
#pragma mark -- 显示信息
- (void)showProcessingHudWithMessage:(NSString *)message {
    [SVProgressHUD showWithStatus:message];
}
- (void)showInfoWithStatusHudWithMessage:(NSString *)message {
    [SVProgressHUD showInfoWithStatus:message];
}
- (void)dismissHudWithDelay:(NSTimeInterval)delay {
    [SVProgressHUD dismissWithDelay:delay];
}
#pragma maek -- 显示SVProgressHUD
- (void)showProcessingHud {
    [SVProgressHUD show];
}
#pragma mark -- 成功的显示SVProgressHUD
- (void)showSuccessHudWithMessage:(NSString *)message {
    [SVProgressHUD showSuccessWithStatus:message];
}
#pragma mark -- 失败的显示SVProgressHUD
- (void)showErrorHudWithMessage:(NSString *)error {
    [SVProgressHUD showErrorWithStatus:error];
}
#pragma mark -- 移除SVProgressHUD
- (void)dismissHud {
    [SVProgressHUD dismiss];
}

- (NSString *)getTime:(NSDate *)date Formatter:(NSString *)str {
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:str ? str:@"YYYY/MM/dd hh:mm:ss SS"];
    NSString *dateString = [dateFormatter stringFromDate:date];
    return dateString;
}

- (UIImage *)scaleToSize:(UIImage *)image size:(CGSize)size {
    //创建一个bitmap的context
    //并把他设置成当前的context
    UIGraphicsBeginImageContext(size);
    //绘制图片的大小
    [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
    //从当前context中创建一个改变大小后的图片
    UIImage *endImage=UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    return endImage;
}

@end
